﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

///<summary>
///
///</summary>
public class StateManager :MonoBehaviour
{

    public bool OpenEndPanel;
    public bool OpenShopPanel;
    public bool OpenPanel;

    public bool IsSkipGameScnen = false;
    public bool IsSkipStartScnen = false;
    public bool IsSkipEndPanel = false;
    public bool IsSkipShopPanel = false;


    static StateManager instance;
    public static StateManager GetInstance
    {
        get
        {
            if (instance == null)
            {
                instance = FindObjectOfType(typeof(StateManager))as StateManager;
            }
            return instance;
        }
    }
    private StateManager() { }
    State state;
    // Start is called before the first frame update
    public void Init()
    {
        state = new LoadingState();   
    }

    // Update is called once per frame
    void Update()
    {
        state.ExecuteState(GetInstance);    
    }

    public void SetState(State state)
    {
        this.state = state;
        state.InitState(GetInstance);
    }

    private void Awake()
    {
        if (GameObject.FindGameObjectsWithTag("StateManager").Length > 1)
        {
            Destroy(this.gameObject);
        }
        else
        {
            DontDestroyOnLoad(this.gameObject);
        }
    }
}
